import diff from "./diff"

export default class Component {
  constructor(props) {
    this.props = props
  }

  setState(state) {
    // 改变子类的 state 这里的 this 是子类的 this 因为方法是谁调用 this 就指向谁
    this.state = Object.assign({}, this.state, state)
    // 获取最新的 virtualDOM 
    const virtualDOM = this.render()
    // 获取旧的 virtualDOM 对象 进行对比
    const oldDOM = this.getDOM()
    // 获取容器
    const container = oldDOM.parentNode
    // 对比
    diff(virtualDOM, container, oldDOM)
    
  }

  setDOM(dom) {
    this._dom = dom
  }

  getDOM() {
    return this._dom
  }

  updateProps(props) {
    this.props = props
  }

  // 生命周期函数
  componentWillMount() { }

  componentDidMount() { }

  componentWillReceiveProps(nextProps) { }

  shouldComponentUpdate(nextProps, nextState) {
    return nextProps != this.props || nextState != this.state
  }

  componentWillUpdate(nextProps, nextState) { }

  componentDidUpdate(prevProps, preState) { }
  
  componentWillUnmount() { }
}